<template>
	<view class="scroll-style">
		<scroll-view class="scroll-view" scroll-y lower-threshold="50" @scrolltolower="scrolltolower">
			<image class="thumb" :src="model.imgs" mode="aspectFill"></image>
			<view class="title">{{model.title}}</view>
			<view  v-if="model.id" class="jg-box">
				<image :src="model.organizationInfo.logo" mode="aspectFill"></image>
				<text>{{model.organizationInfo.name}}</text>
				<text style="color: #888888; margin-left: 15rpx;">发起筹款</text>
			</view>
			<view class="money-box">
				<view class="money-item">
					<text class="value">{{model.amount | moneyFormatter}}</text>
					<text class="tit">所需筹款(元)</text>
				</view>
				<view class="line"></view>
				<view class="money-item">
					<text class="value">{{model.raiseAmount | moneyFormatter}}</text>
					<text class="tit">已经筹到(元)</text>
				</view>
				<view class="line"></view>
				<view class="money-item">
					<text class="value">{{model.raiseNumber || 0}}</text>
					<text class="tit">帮助次数</text>
				</view>
			</view>
			
			<view class="headline">求助故事</view>
			<view style="margin-top: 30rpx;">
				<u-parse :content="model.content"></u-parse>
			</view>
			
			<block v-if="list.length > 0">
				<view class="headline">爱心帮助记录</view>
				<view style="margin-top: 20rpx;">
					<view v-for="(item, index) in list" :key="index" class="axls-li">
						<image class="avatar" :src="item.avatar" mode="aspectFill"></image>
						<view class="right-box">
							<view class="jc-sb">
								<text class="name">{{item.donateName}}</text>
								<view class="axls-money">
									帮助了
									<text class="money">{{item.money | moneyFormatter}}</text>
									元
								</view>
							</view>
							<text v-if="item.remark" class="remark">{{item.remark}}</text>
							<text class="time">{{item.gmtCreate | timeFormatter}}</text>
						</view>
					</view>
				</view>
			</block>
			<view style="width: 100%; height: 70rpx;"></view>
		</scroll-view>
		<view class="bottom-box">
			<view class="collect-box" @click="clickCollect">
				<block v-if="model.collect">
					<image src="../../static/image/ysc.png"></image>
					<text class="ysc">已收藏</text>
				</block>
				<block v-else>
					<image src="../../static/image/sc.png"></image>
					<text>收藏</text>
				</block>
			</view>
			<view class="status-box highlight" @click="clickDonation">
				<image src="@/static/image/ydl.png"></image>
				<text>我也来帮助</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { detail, collect, donateList } from '@/api/activity/index'
	export default {
		data() {
			return {
				show: false,
				id: undefined,
				model: {},
				page: 1,
				total: 0,
				list: [],
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.loadData();
			this.loadDonateList();
			uni.$on('donationSuccess', response => {
				this.page = 1;
				this.loadData();
				this.loadDonateList();
			})
		},
		onUnload() {
			uni.$off('donationSuccess');
		},
		methods: {
			loadData() {
				detail(this.id, response => {
					this.model = response;
				})
			},
			
			/* 获取捐款记录 */
			loadDonateList() {
				donateList({ activityId: this.id, page: this.page, limit: 10 }, (response, total) => {
					this.total = total;
					if (this.page == 1) {
						this.list = response;
					}else {
						this.list = this.list.concat(response);
					}
				})
			},
			
			/* 点击收藏和取消收藏 */
			clickCollect() {
				collect(this.id, response => {
					this.loadData();
				})
			},
			
			/* 点击捐款 */
			clickDonation() {
				uni.navigateTo({
					url: `support?id=${this.model.id}`
				})
			},
			
			/* 捐款成功 */
			donationSuccess() {
				this.page = 1;
				this.loadData();
				this.loadDonateList();
			},
			
			scrolltolower() {
				if (this.total > this.list.length) {
					this.page++;
					this.loadData();
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-view {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		flex: 1;
		overflow-y: auto;
		padding: 0 30rpx;
	}
	
	.thumb {
		margin-top: 30rpx;
		width: 690rpx;
		height: 400rpx;
		border-radius: 16rpx;
	}
	
	.title {
		margin-top: 20rpx;
		font-size: 40rpx;
		font-weight: bold;
		color: #000000;
		line-height: 60rpx;
	}
	
	.jg-box {
		display: flex;
		align-items: center;
		margin-top: 20rpx;
		font-size: 28rpx;
		color: #000000;
		image {
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			margin-right: 15rpx;
		}
	}
	
	.money-box {
		display: flex;
		align-items: center;
		margin-top: 50rpx;
		justify-content: space-between;
		.money-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 33%;
			.value {
				color: #FEAB43;
				font-size: 45rpx;
				font-weight: bold;
			}
			.tit {
				margin-top: 15rpx;
				color: #414141;
				font-size: 28rpx;
			}
		}
		.line {
			width: 1rpx;
			height: 60rpx;
			background-color: #E3E3E3;
		}
	}
	
	.headline {
		margin-top: 50rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #000000;
	}
	
	.axls-li {
		display: flex;
		padding: 40rpx 0;
		border-bottom: 1rpx solid #E3E3E3;
		.avatar {
			width: 90rpx;
			height: 90rpx;
			border-radius: 50%;
		}
		.right-box {
			display: flex;
			flex-direction: column;
			flex: 1;
			margin-left: 20rpx;
			.jc-sb {
				display: flex;
				align-items: center;
				justify-content: space-between;
				.name {
					color: #000000;
					font-size: 28rpx;
					font-weight: bold;
				}
				.axls-money {
					display: flex;
					align-items: center;
					color: #000000;
					font-size: 28rpx;
					font-weight: bold;
					flex-shrink: 0;
					.money {
						font-size: 40rpx;
						color: #FEAB43;
						margin: 0 8rpx;
					}
				}
			}
			
			.remark {
				margin-top: 15rpx;
				color: #333333;
				font-size: 27rpx;
			}
			
			.time {
				margin-top: 10rpx;
				color: #999999;
				font-size: 24rpx;
			}
		}
	}
	
	.bottom-box {
		display: flex;
		align-items: center;
		box-shadow: 0px -4px 16px 1px rgba(0,0,0,0.1);
		padding: 10rpx 40rpx;
		box-sizing: border-box;
		.collect-box {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			color: #5D5D5D;
			width: 160rpx;
			text {
				margin-top: 5rpx;
			}
			image {
				width: 40rpx;
				height: 38rpx;
				margin-right: 10rpx;
			}
			.ysc {
				color: #FA7E04;
			}
		}
		
		.status-box {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: 10rpx;
			height: 80rpx;
			line-height: 80rpx;
			flex: 1;
			background-image: linear-gradient(to right, #D9D9D8, #9A9B9A);
			border-radius: 80rpx;
			font-size: 28rpx;
			color: #fff;
			image {
				width: 45rpx;
				height: 37rpx;
				margin-right: 40rpx;
			}
			&.highlight {
				background-image: linear-gradient(to right, #F49C01, #ED810E);
			}
		}
	}
</style>